package io.lkt.modules.sys.service.impl;

import io.lkt.commons.dynamic.datasource.annotation.DataSource;
import io.lkt.modules.sys.dao.BArticleInfoDao;
import io.lkt.modules.sys.dao.BBusinessDictDao;
import io.lkt.modules.sys.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;

import io.lkt.modules.sys.dao.BBrandInfoDao;
import io.lkt.modules.sys.service.BBrandInfoService;


@Service("bBrandInfoService")
public class BBrandInfoServiceImpl extends ServiceImpl<BBrandInfoDao, BBrandInfoEntity> implements BBrandInfoService {
    @Autowired
    BBrandInfoDao brandInfoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BBrandInfoEntity> page = this.page(
                new Query<BBrandInfoEntity>().getPage(params),
                new QueryWrapper<BBrandInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<BBrandNameEntity> queryAll(Integer id) {
        return brandInfoDao.queryAll(id);
    }

    @Override
    public BBrandInfoEntity queryByName(String brandName) {
        return brandInfoDao.queryByName(brandName);
    }

    @Override
    public BBrandInfoEntity queryNameById(Integer id) {
        return brandInfoDao.queryNameById(id);
    }

    @Override
    public List<Integer> queryByNameLike(String brandName) {
        return brandInfoDao.queryByNameLike(brandName);
    }

    @Override
    public BBrandInfoEntity queryTempByName(String brandName) {
        return brandInfoDao.queryTempByName(brandName);
    }

    @Override
    public int addBrandAndType(Map<String, Object> map) {
        return brandInfoDao.addBrandAndType(map);
    }

    @Override
    public int upType(Map<String, Object> map) {
        return brandInfoDao.upType(map);
    }

    @Override
    public List<BBrandInfoEntity> typeByBrandId(Integer brandId) {
        return brandInfoDao.typeByBrandId(brandId);
    }

    @Override
    public Integer queryByAlias(String brandName) {
        return brandInfoDao.queryByAlias(brandName);
    }

    @Override
    public int delBrandAndType(Integer brandId) {
        return brandInfoDao.delBrandAndType(brandId);
    }

    @Override
    public int delsupply(Integer brandId) {
        return brandInfoDao.delsupply(brandId);
    }

    @Override
    @DataSource("master")
    public BBrandInfoEntity getById(Serializable id){
        return (BBrandInfoEntity)((BBrandInfoDao)this.baseMapper).selectById(id);
    }

    @Override
    @DataSource("master")
    public boolean save(BBrandInfoEntity entity)
    {
        return retBool(Integer.valueOf(((BBrandInfoDao)this.baseMapper).insert(entity)));
    }

    @Override
    @DataSource("master")
    public boolean updateById(BBrandInfoEntity entity)
    {
        return retBool(Integer.valueOf(((BBrandInfoDao)this.baseMapper).updateById(entity)));
    }

    public List<BBrandVitalEntity> queryVital(Map<String, Object> map)
    {
        return this.brandInfoDao.queryVital(map);
    }

    public Integer queryVitelTotal(Map<String, Object> map)
    {
        return this.brandInfoDao.queryVitelTotal(map);
    }

    @Override
    public List<BBrandCategoryEntity> getAllCategory() {
        BBrandCategoryEntity bBrandCategoryEntity = new BBrandCategoryEntity();
        bBrandCategoryEntity.setCategoryFlag(1);//展示状态（0停用 1正常）
        return this.brandInfoDao.queryAllCategory(bBrandCategoryEntity);
    }

    @Override
    public int updateBrandAlias(BBrandInfoEntity brandInfo) {
        brandInfo.setModifyTime(new Date());
        return this.brandInfoDao.updateBrandAlias(brandInfo);
    }

}
